; 功能：数字转字符串
; AL   in/out  转换内容
btoa:
	cmp al, 0ah
	jae BTOA_REST
	add al, 30h
	ret
 BTOA_REST:
	add al, 37h
	ret

PrintChar:
	push ax
	push bx
	push cx
	mov ah, 0eh
	mov bl, 8fh
	mov cx, 1
	int 10h
	pop cx
	pop bx
	pop ax
	ret


; 功能：输出字节
; AL		输出内容
PrintByte:
	push dx
	mov dl, al
	shr al, 4
	and al, 0fh
	call btoa
	call PrintChar
	mov al, dl
	and al, 0fh
	call btoa
	call PrintChar
	pop dx
	ret

; PrintWord(WORD w)
; 功能：输出字节
; w		输出内容
PrintWord:
	push ax
	mov ax, [esp + 4]
	ror ax, 8
	call PrintByte
	ror ax, 8
	call PrintByte
	pop ax
	ret 2


PrintDWord:
	push eax
	mov eax, [esp + 8]
	rol eax, 8
	call PrintByte
	rol eax, 8
	call PrintByte
	rol eax, 8
	call PrintByte
	rol eax, 8
	call PrintByte
	pop eax
	ret 4


; PrintLongHex(byte hex[], int size)
; 以16进制输出字符串
; hex 	16进制数组
; size	数组长度
PrintLongHex:
	pushad
	mov ecx, [esp+8]
	lea esi, [esp+4]
LB_PRINT_BYTE:
	mov al, [esi]
	and al, 0fh
	add al, 30h
	call PrintByte
	inc esi
	loop LB_PRINT_BYTE
	popad
	ret 8


; PrintStringRM(char *str)
; 输出以NULL结尾的字符串
PrintStringRM:
	 push ax
	 push si
 	 mov si, [esp + 6]
	 jmp LB_RM_ISNULL
 LB_RM_PRINTC:	
	 call PrintChar
	 inc si
 LB_RM_ISNULL:
	 mov al, [si]
	 test al, al
	 jnz LB_RM_PRINTC
	 pop si
	 pop ax
	 ret 2


; PrintStringPM(char *str)
; 输出以NULL结尾的字符串
PrintStringPM:
	 mov esi, [esp + 4]
	 jmp LB_PM_ISNULL
 LB_PM_PRINTC:	
	 call PrintChar
	 inc esi
 LB_PM_ISNULL:
	 mov al, [esi]
	 test al, al
	 jnz LB_PM_PRINTC
	 ret 4

PrintSpacing:
	push ax
	mov al, ' '
	call PrintChar
	pop ax
	ret

PrintEndLine:
	push ax
	mov al, 0x0d
	call PrintChar
	mov al, 0x0a
	call PrintChar
	pop ax
	ret


; 比较两个字符创是否相等
; @param [#1]		第一个字符串首地址
; @param [#2] 		第二个字符串首地址
; @return 非0 		相等
; 			0		不相等
Compare:
	push bx
	push dx
	push cx
	mov ax, word [esp + 8]		; 第一个字符串
	mov dx, word [esp + 10]		; 第二个字符串
	jmp cmpchar
incrase:
	add dx, 1
	add bx, 1
cmpchar:
	mov bx, ax
	cmp byte [bx], 0
	jz loopend
	mov bx, dx
	cmp byte [bx], 0
	jz false
	mov bx, ax
	mov cl, byte [bx]
	mov bx, dx
	test cl, byte [bx]
	jnz incrase
loopend:
	mov bx, dx
	cmp byte [bx], 0
	jnz false
true:
	mov ax, 1
	jmp finish
false:
	xor ax, ax
finish:
	pop cx
	pop dx
	pop bx
	ret